<?php
/*
 * SiteMap生成索引类
 */
class Libs_SiteMap_Index extends Libs_SiteMap_Base{

    function __construct(){
        
		$this->head = '<?xml version="1.0" encoding="UTF-8" ?>';
		$this->head .="\n";
		$this->head .= '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
		$this->head .="\n";
		$this->footer = '</sitemapindex>';

    }

    /**
     * 生成链接区域
     * @param array $dataArr 数据数组 loc lastmod changefreq priority
     */
    function createSection(&$dataArr){
        $outstr = '';
        foreach ($dataArr as $data) {
        	$outstr .= "<sitemap>\n";
			$outstr .= "<loc>".$data['loc']."</loc>\n";
        	if(!empty($data['lastmod']))$outstr .= "<lastmod>".$data['lastmod']."</lastmod>\n";
        	$outstr .= "</sitemap>\n";
        }
        return $outstr;
    }
    /**
     * 产生索引数据，并生成索引文件
     *
     * @param $indexPath 索引文件地址
     * @param $xmlfileCnt XML文件数量
     * @param $xmlfilePre XML文件前缀 如 http://mobile.zol.com.cn/sitemap_thread_
     * @param $rsync   是否同步
     * @param $gizp    是否压缩
     */
    function CreateData($indexPath,$xmlfileCnt,$xmlfilePre,$gzip=false,$extendsXmls=array()){
        $dataArr = array();
        $nowdt = date('Y-m-d');
        $gzips = $gzip ? '.gz' : '';
        for ($i=$xmlfileCnt;$i>0;$i--){
            $dataArr[] = array(
                                 'loc'       =>  $xmlfilePre.$i.'.xml'.$gzips,
                                 'lastmod'   =>  $nowdt,
                              );
        }
        if($extendsXmls){
            foreach ($extendsXmls as $xml){
                $dataArr[] = array(
                                     'loc'       =>  $xml.$gzips,
                                     'lastmod'   =>  $nowdt,
                                  );

            }
        }
        $this->createContent($dataArr,$indexPath,$rsync,false);
    }
}


?>
